package com.tangshuai;

import com.alibaba.fastjson.JSONObject;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

public class TestMulti {

    public static void main(String[] args) {
        // 1. new jedis 对象即可
        Jedis jedis = new Jedis("115.29.241.140",4352);
        jedis.auth("0602");
        //jedis 所有的命令就是我们之前学习的所有指令

        jedis.flushDB();

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("hello","world");
        jsonObject.put("name","tangshuai");

        Transaction multi = jedis.multi();
        String result  = jsonObject.toJSONString();
        //jedis.watch();
        try {
            multi.set("user1",result);
            multi.set("user2",result);
            int i   =1/0;
            multi.exec();
        } catch (Exception e) {
            multi.discard();
            e.printStackTrace();
        } finally {
            System.out.println(jedis.get("user1"));
            System.out.println(jedis.get("user2"));
            jedis.close();
        }

    }


}
